﻿Imports Mysoft.Map.Data
Imports Mysoft.Map.Utility
Imports Mysoft.Map.Workflow
Partial Public Class SelectCompany
    Inherits Mysoft.Map.Application.Security.AppPage

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If Not IsPostBack Then
            repLD.BindMode = 1
            repLD.DataTable = GetBusinessUnitDataTable()
            repLD.DataBind()
        End If
    End Sub

    Private Function GetBusinessUnitDataTable() As DataTable
        Dim SQL As String
            SQL = " SELECT Hierarchycode AS code, BUName AS name, BUGUID AS guid, '0' AS type,'0' AS checked,AllowSelect=1" & _
                  " FROM myBusinessUnit WHERE (2=2)" & _
                  " UNION " & _
                " SELECT Bu.Hierarchycode AS code, Bu.BUName AS name, Bu.BUGUID AS guid, '0' AS type,'0' AS checked,AllowSelect=0" & _
                  " FROM myBusinessUnit Bu Inner Join MyBuToBu BB ON Bu.BuGUID = BB.BuGUID" & _
                  " WHERE (3=3)" & _
                  " ORDER BY code"

        Dim strFilter As String
        strFilter = "Select s.CompanyGUID  FROM myStationUser su  Join myStation s ON su.StationGUID = s.StationGUID WHERE su.UserGUID = '" & Session("UserGUID") & "'"
        SQL = SQL.Replace("2=2", "BuGUID IN (" + strFilter + ")")
        SQL = SQL.Replace("3=3", "BB.SubBuGUID IN (" + strFilter + ") AND BB.BuGUID NOT IN (" + strFilter + ")")



        GetBusinessUnitDataTable = MyDB.GetDataTable(SQL)

    End Function

End Class